﻿namespace FSharpLib
open System

type Prize(d, v) =
    let description = d : string
    let value = v : int
    member this.Description = description
    member this.Value = value

[<AbstractClass>]
type KujibikiProcesser() =
    abstract GetPrize : unit -> Prize

type internal KujibikiProcesser_Kaden() =
    inherit KujibikiProcesser()
    let random = new Random()
    override this.GetPrize() = 
        match random.Next(1,100) with
        | n when n >= 1 && n <= 25 ->
            new Prize("カメラです", 20000)
        | n when n >= 26 && n <= 50 ->
            new Prize("Androidじゃないほうのスマホです", 50000)
        | _ ->
            new Prize("ハズレwww", 0)

type Kujibiki =
    val mutable private insertedCoin : int
    val mutable private kujiProc : KujibikiProcesser
    val mutable private oneGameCoin : int

    new () =
         {insertedCoin = 0; kujiProc = new KujibikiProcesser_Kaden(); oneGameCoin = 100}
    internal new(proc) =
         {insertedCoin = 0; kujiProc = proc; oneGameCoin = 100}

    member this.OneGameCoin with get() = this.oneGameCoin
                                and set newVal = this.oneGameCoin <- newVal

    member this.InsertCoin(coin) = this.insertedCoin <- this.insertedCoin + coin

    member this.DrawLottery() = 
        if this.insertedCoin < this.OneGameCoin then
            raise <| Exception("一回" + this.OneGameCoin.ToString() + "コインが必要です。")
        this.insertedCoin <- this.insertedCoin - this.oneGameCoin
        this.kujiProc.GetPrize()
        
        